﻿
using System;
using System.Collections;
using System.Collections.Generic;

public static class CoroutineService
{
	static List<CoroutineCenter> ccList;
	
	public static void Initialize()
	{
		ccList = new List<CoroutineCenter>();
		ccList.Add(new CoroutineCenter());
	}
	
	public static void Update(float deltaTime)
	{
		ccList.ForEach(i => i.Update(deltaTime));
	}
	
	public static IEnumerator StartCoroutine(IEnumerator it)
	{
		return ccList[0].StartCoroutine(it);
	}

	public static IEnumerator StartCoroutine(IEnumerator it, float millisecond)
	{
		return ccList[0].StartCoroutine(it, millisecond);
	}
	
	public static void StopCoroutine(IEnumerator it)
	{
		ccList[0].StopCoroutine(it);
	}
	
	public static void StopAllCoroutine()
	{
		ccList.ForEach(i => i.StopAllCoroutine());
	}
	
	public static void AddCenter(CoroutineCenter center)
	{
		if (ccList.IndexOf(center) < 0)
			ccList.Add(center);
	}
	
	public static void RemoveCenter(CoroutineCenter center)
	{
		DebugUtil.Assert(ccList != null);
		ccList.Remove(center);
	}
}